NextJs / APIs / Post Data
POST DATA
-
Step
Complete code
'use client' import React from 'react'; import { useState, useEffect } from "react"; export default function Home() { const [title, setTitle] = useState('') const [body, setBody] = useState('') const submitData = async () => { let response = await fetch('https://jsonplaceholder.typicode.com/posts', { method: 'POST', body: JSON.stringify({ title: title, body: body, userId: 1 }), headers: { 'Content-type': 'application/json' } }) response = await response.json() alert(JSON.stringify(response)) } return ( <> External Post API Request | GeeksForGeeks
setTitle(e.target.value)} placeholder='Enter Post Title' /> setBody(e.target.value)} placeholder='Enter Post Body' /> > ); }